<template>
  <div class="svg-converter">
    <div class="container">
      <!-- 标题 -->
      <div class="header">
        <h1>
          <img src="https://free-1325650170.cos.ap-guangzhou.myqcloud.com/free_convert/freeconvert-logo.svg" alt="FreeConvert Logo" class="logo-icon"/>
          文件转SVG在线工具
        </h1>
        <p class="subtitle">快速将图像文件转换为SVG矢量图，支持多种格式</p>
      </div>

      <!-- 上传与预览区域 -->
      <div class="upload-section">
        <div v-if="!selectedFile && !isUploading"
          class="upload-area" 
          :class="{ 'drag-over': isDragOver }"
          @drop.prevent="handleDrop"
          @dragover.prevent="isDragOver = true"
          @dragleave.prevent="isDragOver = false"
        >
          <input 
            type="file" 
            ref="fileInput" 
            accept="image/*"
            @change="handleFileSelect"
            style="display: none"
          />
          
          <div class="upload-placeholder">
            <div class="upload-icon">📁</div>
            <p class="upload-text">点击选择或拖拽图像文件到这里</p>
            <p class="upload-hint">支持 PNG、JPG、GIF、BMP 等格式，最大20MB</p>
            <button class="select-btn" @click="$refs.fileInput.click()">选择文件</button>
          </div>
        </div>

        <!-- 工作台：左图像预览 / 右参数 -->
        <div v-if="imageUrl" class="workbench">
          <!-- 左侧：图像预览 -->
          <section class="preview-section">
            <div class="image-preview-wrapper">
              <img 
                ref="imagePreview"
                :src="imageUrl" 
                @load="handleImageLoaded"
                class="image-preview"
              />
            </div>
            
            <div class="file-info">
              <p class="file-name">
                <strong>文件名：</strong>
                <span>{{ selectedFile.name }}</span>
              </p>
              <p><strong>文件大小：</strong>{{ formatFileSize(selectedFile.size) }}</p>
              <p v-if="imageWidth && imageHeight"><strong>尺寸：</strong>{{ imageWidth }} × {{ imageHeight }}</p>
            </div>
          </section>

          <!-- 右侧：转换参数 -->
          <aside class="options-section">
            <h3>转换设置</h3>
            
            <div class="option-row size-inputs">
              <div class="option-item">
                <label>宽度 (px)</label>
                <input 
                  v-model.number="conversionOptions.width" 
                  type="number" 
                  :placeholder="imageWidth ? String(imageWidth) : '保持原始'" 
                  min="1" 
                  :disabled="isUploading"
                  @input="handleWidthChange"
                />
              </div>
              <div class="option-item">
                <label>高度 (px)</label>
                <input 
                  v-model.number="conversionOptions.height" 
                  type="number" 
                  :placeholder="imageHeight ? String(imageHeight) : '保持原始'" 
                  min="1" 
                  :disabled="isUploading"
                  @input="handleHeightChange"
                />
              </div>
            </div>

            <div class="option-row">
              <div class="option-item full-width">
                <label class="checkbox-label">
                  <input 
                    type="checkbox" 
                    v-model="conversionOptions.keepAspectRatio"
                    :disabled="isUploading"
                  />
                  <span>保持宽高比</span>
                </label>
              </div>
            </div>

            <div class="option-row">
              <div class="option-item full-width">
                <label>矢量化精度 (1-10)</label>
                <div class="slider-container">
                  <input 
                    v-model.number="conversionOptions.precision" 
                    type="range" 
                    min="1" 
                    max="10" 
                    class="custom-slider"
                    :disabled="isUploading"
                  />
                  <div class="range-value">{{ conversionOptions.precision }}</div>
                </div>
                <small>值越高越精细，颜色越丰富</small>
              </div>
            </div>

            <button class="convert-btn" @click="handleConvert" :disabled="isUploading">
              <span v-if="!isUploading">开始转换</span>
              <span v-else class="converting-content">
                <span class="spinner-small"></span>
                转换中...
              </span>
            </button>
          </aside>
          <!-- 新增：移动端固定底部按钮，与VideoToGIF页面一致 -->
          <div v-if="imageUrl" class="mobile-convert-btn-wrapper">
            <button class="mobile-convert-btn" @click="handleConvert" :disabled="isUploading">
              <span v-if="!isUploading">开始转换</span>
              <span v-else class="converting-content">
                <span class="spinner-small"></span>转换中...
              </span>
            </button>
          </div>
        </div>
      </div>

      <section class="tips-card">
        <h3>为什么选择 FreeConvert 文件转SVG？</h3>
        <ul>
          <li>矢量化算法保留线条与色块细节，放大也保持清晰锐利</li>
          <li>自由设置尺寸、精度与颜色数量，适配 Logo、插画、CAD 等场景</li>
          <li>上传后即时在浏览器端处理，临时文件定期清理，素材更安全</li>
        </ul>
      </section>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onUnmounted, onBeforeUnmount, watch } from 'vue'
import { useRouter, onBeforeRouteLeave } from 'vue-router'
import { uploadAndConvertToSvg } from '@/api/conversion'
import { toastError } from '@/utils/toast'

const router = useRouter()

// 状态变量
const selectedFile = ref(null)
const imageUrl = ref('')
const isUploading = ref(false)
const isDragOver = ref(false)
const fileInput = ref(null)
const imagePreview = ref(null)
const imageWidth = ref(0)
const imageHeight = ref(0)

// 转换选项
const conversionOptions = reactive({
  width: null,
  height: null,
  keepAspectRatio: true,
  precision: 8  // 默认高精度，自动控制颜色数量
})

// 原始宽高比
const originalAspectRatio = ref(1)

// 文件选择处理
const handleFileSelect = (event) => {
  const file = event.target.files[0]
  if (file) {
    processFile(file)
  }
}

// 拖拽处理
const handleDrop = (event) => {
  isDragOver.value = false
  const file = event.dataTransfer.files[0]
  if (file) {
    processFile(file)
  }
}

// 🔑 清理对象URL
const cleanupObjectURL = () => {
  if (imageUrl.value && imageUrl.value.startsWith('blob:')) {
    try {
      URL.revokeObjectURL(imageUrl.value)
    } catch (error) {
      console.warn('清理对象URL失败:', error)
    }
  }
}

// 处理文件
const processFile = (file) => {
  // 验证文件类型
  if (!file.type.startsWith('image/')) {
    toastError('请选择图像文件')
    return
  }
  
  // 验证文件大小（20MB）
  if (file.size > 20 * 1024 * 1024) {
    toastError('文件大小不能超过20MB')
    return
  }
  
  // 🔑 清理之前的对象URL
  cleanupObjectURL()
  
  selectedFile.value = file
  imageUrl.value = URL.createObjectURL(file)
}

// 图像加载完成
const handleImageLoaded = () => {
  if (imagePreview.value) {
    imageWidth.value = imagePreview.value.naturalWidth
    imageHeight.value = imagePreview.value.naturalHeight
    
    // 计算原始宽高比
    if (imageHeight.value > 0) {
      originalAspectRatio.value = imageWidth.value / imageHeight.value
    }
    
    // 自动填充原始尺寸到输入框
    if (!conversionOptions.width) {
      conversionOptions.width = imageWidth.value
    }
    if (!conversionOptions.height) {
      conversionOptions.height = imageHeight.value
    }
  }
}

// 宽度变化时自动调整高度
const handleWidthChange = () => {
  if (conversionOptions.keepAspectRatio && conversionOptions.width && originalAspectRatio.value) {
    conversionOptions.height = Math.round(conversionOptions.width / originalAspectRatio.value)
  }
}

// 高度变化时自动调整宽度
const handleHeightChange = () => {
  if (conversionOptions.keepAspectRatio && conversionOptions.height && originalAspectRatio.value) {
    conversionOptions.width = Math.round(conversionOptions.height * originalAspectRatio.value)
  }
}

// 格式化文件大小
const formatFileSize = (bytes) => {
  if (bytes < 1024) return bytes + ' B'
  if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB'
  return (bytes / (1024 * 1024)).toFixed(2) + ' MB'
}

// 开始转换
const handleConvert = async () => {
  if (!selectedFile.value || isUploading.value) {
    return
  }
  
  isUploading.value = true
  
  try {
    // 构建FormData
    const formData = new FormData()
    formData.append('file', selectedFile.value)
    
    if (conversionOptions.width) {
      formData.append('width', conversionOptions.width)
    }
    if (conversionOptions.height) {
      formData.append('height', conversionOptions.height)
    }
    formData.append('keepAspectRatio', conversionOptions.keepAspectRatio)
    formData.append('precision', conversionOptions.precision)
    // colorCount由后端根据precision自动计算
    
    // 上传并转换
    const response = await uploadAndConvertToSvg(formData)
    
    // 保存结果到sessionStorage
    sessionStorage.setItem('conversionResult', JSON.stringify(response.data))
    
    // 跳转到SVG成功页面
    router.push('/svg-success')
  } catch (error) {
    // 显示错误信息
    const errorMsg = error.message || '网络错误，稍后重试'
    toastError(errorMsg)
  } finally {
    isUploading.value = false
  }
}

// 🔑 监听路由变化，清理对象URL
onBeforeRouteLeave((to, from, next) => {
  cleanupObjectURL()
  next()
})

// 🔑 组件卸载时清理对象URL
onBeforeUnmount(() => {
  cleanupObjectURL()
})

onUnmounted(() => {
  cleanupObjectURL()
})

// 🔑 监听imageUrl变化，自动清理旧的对象URL
watch(imageUrl, (newUrl, oldUrl) => {
  if (oldUrl && oldUrl.startsWith('blob:')) {
    try {
      URL.revokeObjectURL(oldUrl)
    } catch (error) {
      console.warn('清理旧对象URL失败:', error)
    }
  }
})
</script>

<style scoped>
.svg-converter {
  min-height: 100vh;
  width: 100vw;
  background: #f5f7fa;
  position: relative;
  overflow: hidden;
  margin: 0;
  padding: 0;
  /* 🔑 移动端：防止双击缩放 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 2vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  box-sizing: border-box;
  background: none;
}

.header {
  text-align: center;
  color: #1e293b;
  margin-bottom: 16px;
  animation: fadeInUp 0.8s ease-out;
  flex-shrink: 0;
}

.header h1 {
  font-size: 2rem;
  margin-bottom: 6px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.logo-icon {
  width: 240px;
  height: 180px;
  animation: fadeInUp 0.8s ease-out;
}

.subtitle {
  font-size: 0.9rem;
  color: #64748b;
  font-weight: 400;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.4;
}

.upload-section {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: 100%;
  animation: fadeInUp 0.6s ease-out both;
  box-sizing: border-box;
  /* 🔑 移动端：确保内容可见 */
  overflow: visible;
  min-height: auto;
}

.upload-area {
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: #fafbfc;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: #667eea;
  background: #f0f4ff;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.upload-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}

.upload-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: #374151;
}

.upload-hint {
  color: #6b7280;
  font-size: 0.875rem;
}

.select-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.select-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.workbench {
  width: 100%;
  background: white;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 20px;
  align-items: start;
}

.preview-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  overflow: hidden;
}

.image-preview-wrapper {
  background: #fafbfc;
  border-radius: 8px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  max-height: 600px;
  border: 1px solid #e5e7eb;
  overflow: hidden;
  box-sizing: border-box;
}

.image-preview {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.file-info {
  background: #fafbfc;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.file-info p {
  margin: 0.5rem 0;
  color: #4b5563;
  font-size: 0.9rem;
}

.file-info .file-name {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
}

.file-info .file-name strong {
  flex-shrink: 0;
}

.file-info .file-name span {
  display: inline-block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.options-section {
  background: #fafbfc;
  padding: 1.5rem;
  border-radius: 8px;
  height: fit-content;
  max-height: 100%;
  border: 1px solid #e5e7eb;
  box-sizing: border-box;
  overflow-y: auto;
}

.options-section h3 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: #1f2937;
  font-size: 1.1rem;
  font-weight: 600;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.option-row.size-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.option-row.size-inputs .option-item {
  flex: 1;
  min-width: 0;
}

.option-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-item.full-width {
  grid-column: 1 / -1;
}

.option-item label {
  font-weight: 600;
  color: #374151;
  font-size: 0.875rem;
}

.option-item input[type="number"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  width: 100%;
  box-sizing: border-box;
}

.option-item input[type="number"]:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.option-item small {
  color: #6b7280;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.slider-container {
  position: relative;
  width: 100%;
  margin: 0.5rem 0;
}

.custom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  outline: none;
  padding: 0;
  margin: 0;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
  transition: all 0.2s;
}

.custom-slider::-webkit-slider-thumb:hover {
  background: #5568d3;
  box-shadow: 0 3px 8px rgba(102, 126, 234, 0.6);
  transform: scale(1.1);
}

.custom-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
  transition: all 0.2s;
}

.custom-slider::-moz-range-thumb:hover {
  background: #5568d3;
  box-shadow: 0 3px 8px rgba(102, 126, 234, 0.6);
  transform: scale(1.1);
}

.custom-slider:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.custom-slider:disabled::-webkit-slider-thumb {
  cursor: not-allowed;
}

.custom-slider:disabled::-moz-range-thumb {
  cursor: not-allowed;
}

.range-value {
  text-align: center;
  font-weight: 600;
  color: #667eea;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.convert-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0.875rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 1rem;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.convert-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.convert-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.converting-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1024px) {
  .workbench {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .options-section {
    order: -1;
    max-height: none;
  }
  
  .image-preview-wrapper {
    max-height: 500px;
  }
}

/* 移动端优化 */
@media (max-width: 768px) {
  .container {
    padding: 12px 3vw;
    min-height: auto;
  }
  
  .header {
    margin-bottom: 12px;
  }
  
  .header h1 {
    font-size: 1.3rem;
    flex-direction: column;
    gap: 8px;
  }
  
  .logo-icon {
    width: 120px;
    height: 90px;
  }
  
  .subtitle {
    font-size: 0.85rem;
    padding: 0 8px;
  }
  
  .upload-section {
    padding: 16px;
    border-radius: 12px;
    /* 🔑 移动端：确保内容可见 */
    overflow: visible;
    min-height: auto;
    padding-bottom: 90px; /* 🔑 为固定按钮留出空间 */
  }
  
  .tips-card {
    padding: 18px;
  }
  
  /* 🔑 移动端：为固定按钮留出空间 */
  .workbench {
    padding-bottom: 90px;
  }
  
  .container {
    padding-bottom: 90px;
  }
  
  .upload-area {
    padding: 1.5rem 1rem;
    border-radius: 8px;
  }
  
  .upload-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }
  
  .upload-text {
    font-size: 1rem;
  }
  
  .upload-hint {
    font-size: 0.8rem;
  }
  
  .select-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
    margin-top: 8px;
  }
  
  .workbench {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    border-radius: 12px;
    /* 🔑 移动端：确保内容可见 */
    overflow: visible;
    min-height: auto;
  }
  
  /* 🔑 移动端：确保预览区域和参数区域顺序正确 */
  .preview-section {
    order: 1;
    width: 100%;
    min-height: auto;
    overflow: visible;
  }
  
  .options-section {
    order: 2;
    width: 100%;
    min-height: auto;
    overflow: visible;
    padding: 1.5rem;
    border-radius: 8px;
    max-height: none;
  }
  
  .image-preview-wrapper {
    min-height: 200px;
    max-height: 50vh;
    padding: 1rem;
  }
  
  .convert-btn {
    display: none;  /* 移动端 main button 只在底部显示 */
  }
}
.mobile-convert-btn-wrapper {
  display: none;
}

.tips-card {
  margin-top: 20px;
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
  width: 100%;
  box-sizing: border-box;
}

.tips-card h3 {
  margin: 0 0 12px;
  color: #111827;
  font-size: 1.1rem;
}

.tips-card ul {
  margin: 0;
  padding-left: 18px;
  color: #4b5563;
  line-height: 1.8;
}
@media (max-width: 768px) {
  .mobile-convert-btn-wrapper {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(102, 126, 234, 0.1);
  }
  .mobile-convert-btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
  }
  .mobile-convert-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5568d3 0%, #6340a0 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
  }
  
  .mobile-convert-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
  }
  
  .mobile-convert-btn:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none;
  }
  .mobile-convert-btn .converting-content {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .mobile-convert-btn .spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
}
/* 小屏幕手机优化 */
@media (max-width: 480px) {
  .container {
    padding: 8px 2vw;
  }
  
  .header h1 {
    font-size: 1.1rem;
  }
  
  .logo-icon {
    width: 100px;
    height: 75px;
  }
  
  .subtitle {
    font-size: 0.8rem;
  }
  
  .upload-section {
    padding: 12px;
    /* 🔑 小屏幕：确保内容可见 */
    overflow: visible;
    min-height: auto;
    padding-bottom: 80px; /* 🔑 为固定按钮留出空间 */
  }
  
  /* 🔑 小屏幕：为固定按钮留出空间 */
  .workbench {
    padding-bottom: 80px;
  }
  
  .container {
    padding-bottom: 80px;
  }
  
  .mobile-convert-btn {
    padding: 14px 20px;
    font-size: 1rem;
    min-height: 48px;
  }
  
  .upload-area {
    padding: 1.2rem 0.8rem;
  }
  
  .upload-icon {
    font-size: 2rem;
  }
  
  .upload-text {
    font-size: 0.9rem;
  }
  
  .workbench {
    padding: 12px;
    gap: 12px;
  }
  
  .image-preview-wrapper {
    min-height: 180px;
    max-height: 45vh;
    padding: 0.8rem;
  }
  
  .options-section {
    padding: 1rem;
  }
  
  .option-item input[type="number"] {
    /* 防止iOS自动缩放 */
    font-size: 16px !important;
  }
  
  .tips-card {
    padding: 14px;
  }
}

/* 移动端：优化按钮触摸体验 */
@media (max-width: 768px) {
  .select-btn,
  .convert-btn {
    /* 🔑 移动端：优化触摸反馈 */
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    touch-action: manipulation;
    /* 防止双击缩放 */
    user-select: none;
    -webkit-user-select: none;
  }
  
  /* 🔑 移动端：优化输入框 */
  .option-item input {
    /* 防止iOS自动缩放 */
    font-size: 16px !important;
    /* 优化触摸体验 */
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.1);
  }
}
</style>


